import fs from 'fs';
import path from 'path';

function isDirectoryEmpty(dirPath) {
    const items = fs.readdirSync(dirPath);
    
    if (items.length === 0) return true;
    
    for (const item of items) {
        const fullPath = path.join(dirPath, item);
        if (fs.statSync(fullPath).isDirectory()) {
            if (!isDirectoryEmpty(fullPath)) {
                return false;
            }
        } else {
            return false;
        }
    }
    
    return true;
}

function removeEmptyDirectories(dirPath) {
    const items = fs.readdirSync(dirPath);
    
    for (const item of items) {
        const fullPath = path.join(dirPath, item);
        if (fs.statSync(fullPath).isDirectory()) {
            removeEmptyDirectories(fullPath);
            if (isDirectoryEmpty(fullPath)) {
                fs.rmdirSync(fullPath);
                console.log(`Removed empty directory: ${fullPath}`);
            }
        }
    }
}

const buildDir = './Build/BariumUnminified';
const buildDir2 = './Build/Barium';
if (fs.existsSync(buildDir)) {
    removeEmptyDirectories(buildDir);
    console.log('Empty directory cleanup completed.');
} 
if (fs.existsSync(buildDir2)) {
    removeEmptyDirectories(buildDir2);
    console.log('Empty directory cleanup completed.');
} 